package com.song.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.song.config.RabbitConfig;
import com.song.domain.Product;
import com.song.entity.R;
import com.song.service.ProductService;
import com.song.mapper.ProductMapper;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
* @author Administrator
* @description 针对表【t_product】的数据库操作Service实现
* @createDate 2024-06-15 09:59:16
*/
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product>
    implements ProductService{

    @Resource
    private RabbitTemplate rabbitTemplate;
    @Override
    public R findById(Long id) {
        Product product = baseMapper.selectById(id);
        //利用RabbitMQ 发送消息给队列
        // rabbitTemplate.convertAndSend(RabbitConfig.EXCHANGE_NAME,"orders.buy",product);
        if(product!=null) {
            rabbitTemplate.convertAndSend(RabbitConfig.EXCHANGE_NAME, "orders.buy", product);
            return R.success(product);
        }
        return  R.error(501,"商品不存在");
    }
}




